
import Vue from 'vue';
import Vuex from 'vuex';

import createPersistedState from 'vuex-persistedstate';
Vue.use(Vuex);

export default new Vuex.Store({

  state: {
    allocations_vuex: [],
    name: '',
    picture:'',
    SelectList:[]
  },
  mutations: {
    permission_id_mu(state, data) {

      state.allocations_vuex.push(data);
      console.log("选中的id:",state.allocations_vuex)
      
    },
    setUserName(state, data) {
      state.name = data;
      console.log('Mutation: name set to', data);
      console.log('State: name', state.name);
    },
    setUserPicture(state,data){
      state.picture = data;
      console.log('Mutation: name set to', data);
      console.log('State: name', state.picture);
    },
    SelectedMu(state,data){
      if(data == []){
        return
      }else{
        state.SelectList.push(data)
      }
      console.log("vuex:",state.SelectList)
    }
  },
  actions: {
    permission_id_ac(context, data) {
      context.commit('permission_id_mu', data);
    },
    setUserNameAction(context, data) {
      context.commit('setUserName', data);
    },
    setUserPictureAction(context,data){
      context.commit('setUserPicture',data)
    },
  },
  plugins: [
    createPersistedState({
      key: 'repaire', // 存储状态的键名，默认为'vuex'
      paths:['name','picture'],// 需要持久化的state名称、state模块名称
      storage: window.localStorage, // 指定存储方式，默认为localStorage
    })
  ]
});